<template>
	<picker mode="date" :value="date" :start="startDate()" :end="endDate()" fields="month" @change="bindDateChange">
		{{date?date:'全部时间'}}
	</picker>
</template>
<script setup lang="ts">
	import {
		ref, toRefs, watch, onMounted, nextTick, computed
	} from "vue";

	const props = defineProps({
		//子组件接收父组件传递过来的值
		showpopup: Boolean,
		workId: String,
		setTimeObj: Object,
		dataChange: String
	})
	// const scrollRef=ref()
	//使用父组件传递过来的值
	const { showpopup, workId, setTimeObj, dataChange } = toRefs(props)
	const emits = defineEmits(['set-popup', 'change'])
	const date = ref('')

	const bindDateChange = (e) => {
		date.value = e.detail.value
		emits('change', date.value)
	}
	function getDate(type) {

		const date = new Date();
		let year = date.getFullYear();
		let month : any = date.getMonth() + 1;
		let day : any = date.getDate();

		if (type === 'start') {
			year = year - 10;
		} else if (type === 'end') {
			year = year;
		} else if (type.format) {
			month = month > 9 ? month : '0' + month;
			return `${year}-${month}`;
		}
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
		return `${year}-${month}`;
	}
	const startDate = () => getDate('start')
	const endDate = () => getDate('end')
	watch(dataChange, (n) => {
		if (!dataChange.value) {
			date.value = ''
		}
	})
	onMounted(() => {
		// date.value = getDate({
		// 	format: true
		// })
		// emits('change',date.value)
	})
</script>

<style>
</style>